/*
 * Copyright (C) 2023 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.xuexiang.templateproject.fragment.news;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.xuexiang.templateproject.R;
import com.xuexiang.templateproject.core.BaseFragment;
import com.xuexiang.templateproject.core.BroadCastManager;
import com.xuexiang.templateproject.databinding.FragmentGridItemBinding;
import com.xuexiang.xpage.annotation.Page;
import com.xuexiang.xrouter.annotation.AutoWired;
import com.xuexiang.xrouter.launcher.XRouter;
import com.xuexiang.xui.widget.imageview.IconImageView;
import com.xuexiang.xui.widget.imageview.RadiusImageView;
import com.xuexiang.xutil.tip.ToastUtils;

@Page
public class GridItemFragment2 extends BaseFragment<FragmentGridItemBinding> {

    public static final String KEY_TITLE_NAME = "title_name2";

    /**
     * 自动注入参数，不能是private
     */
    @AutoWired(name = KEY_TITLE_NAME)
    String title;

    @NonNull
    @Override
    protected FragmentGridItemBinding viewBindingInflate(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, boolean attachToRoot) {
        return FragmentGridItemBinding.inflate(inflater, container, attachToRoot);
    }

    @Override
    protected void initArgs() {
        // 自动注入参数必须在initArgs里进行注入
        XRouter.getInstance().inject(this);
    }

    @Override
    protected String getPageTitle() {
        return title;
    }


    @Override
    protected void initViews() {
        TextView jiance=findViewById(R.id.jiance);
        RadiusImageView heart=findViewById(R.id.heart);
        jiance.setVisibility(View.GONE);
        heart.setVisibility(View.GONE);
        IconImageView sad = findViewById(R.id.sad);
        IconImageView normal = findViewById(R.id.normal);
        IconImageView angry = findViewById(R.id.angry);
        IconImageView happy = findViewById(R.id.happy);
        Intent intent = new Intent();
        intent.setAction("p");

        sad.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                intent.putExtra("opt", "1");
                BroadCastManager.getInstance().sendBroadCast(requireActivity(), intent);
                ToastUtils.toast("向前看,不开心的事情总会过去!");
                requireActivity().onBackPressed();
            }
        });
        normal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent.putExtra("opt", "2");
                BroadCastManager.getInstance().sendBroadCast(requireActivity(), intent);
                ToastUtils.toast("岁月静好");
                requireActivity().onBackPressed();

            }
        });
        angry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                intent.putExtra("opt", "3");
                BroadCastManager.getInstance().sendBroadCast(requireActivity(), intent);
                ToastUtils.toast("忍一时风平浪静,退一步海阔天空。");
                requireActivity().onBackPressed();

            }
        });
        happy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                intent.putExtra("opt", "4");

                BroadCastManager.getInstance().sendBroadCast(requireActivity(), intent);
                ToastUtils.toast("永远开心！");
                requireActivity().onBackPressed();

            }
        });

    }
}
